/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controlador;

import Facade.MaquinariaFacade;
import VO.MaquinariaVO;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author Jorge
 */
public class MaquinariaAction extends DispatchAction {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    private final static String MODIFY = "modificar";
    private final static String DELETE ="eliminar";
    private final static String CONSULT ="consultar";
    private final static String HOME ="inicio";
    private final static String BACK ="volver";
    private final static String BITACORA ="bitacora";

    /**
     * This is the Struts action method called on
     * http://.../actionPath?method=myAction1,
     * where "method" is the value specified in <action> element : 
     * ( <action parameter="method" .../> )
     */
    public ActionForward ingresarMaq(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        return mapping.findForward(SUCCESS);
    }

    /**
     * This is the Struts action method called on
     * http://.../actionPath?method=myAction2,
     * where "method" is the value specified in <action> element : 
     * ( <action parameter="method" .../> )
     */
    public ActionForward modificarMaq(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        MaquinariaFacade fcdMaquinaria = new MaquinariaFacade();
        Vector listaMaquinas = fcdMaquinaria.cargarNomenclaturas();

        request.getSession().setAttribute("listaMaquinas",listaMaquinas);
        
        return mapping.findForward(MODIFY);
    }

    public ActionForward bitacora(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        MaquinariaFacade fcdMaquinaria = new MaquinariaFacade();
        Vector listaMaquinas = fcdMaquinaria.cargarNomenclaturas();

        request.setAttribute("listaMaquinarias",listaMaquinas);

        return mapping.findForward(BITACORA);
    }

    public ActionForward eliminarMaq(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        MaquinariaFacade fcdMaquinaria = new MaquinariaFacade();
        Vector listaMaquinas = fcdMaquinaria.cargarNomenclaturas();

        request.getSession().setAttribute("listaMaquinas",listaMaquinas);

        return mapping.findForward(DELETE);
    }

     public ActionForward consultarMaq(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        MaquinariaFacade fcdMaquinaria = new MaquinariaFacade();
        Vector listaMaquinas = fcdMaquinaria.listarMaquinarias();

        
        request.setAttribute("Maquinas",listaMaquinas);

        return mapping.findForward(CONSULT);
    }



      public ActionForward volver(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {



        return mapping.findForward(BACK);
    }
       public ActionForward inicio(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {



        return mapping.findForward(HOME);
    }
}